package me.zixing.timer.ui;

import me.zixing.timer.core.ImageTime;
import me.zixing.timer.core.ImageTimeElement;
import me.zixing.timer.core.TimeComputUtil;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.util.concurrent.TimeUnit;

/**
 * Created by bingh on 2017/10/21.
 */
public class DashBoardPanel extends JPanel {

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        drawComput(g);
    }

    public void reShow(){
        while(!TimeComputUtil.stopComput){
            try{
               TimeUnit.MILLISECONDS.sleep(500);
               this.repaint();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    public void drawComput(Graphics g){

        try{
            ImageTime imageTime = ImageTime.parseTime();
            for (ImageTimeElement element:imageTime) {
                g.drawImage(ImageIO.read(element.getFileUrl()),element.getX(),element.getY(),element.getWidth(),element.getHeight(),this);

            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }


}
